// author: shelman
// description：定义通用日志输出的宏定义
#pragma once

#include <iostream>
#include <string>
#include <ctime>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 日志的缓存大小
#define COMMON_LOGINFO_SIZE   (2 * 1024)

//定义导出库
#if defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64)

#define COMMONLOG_INFO(fmt, ...) \
    do { \
    char szInfo[COMMON_LOGINFO_SIZE] = {0}; \
    snprintf(szInfo, COMMON_LOGINFO_SIZE - 1, fmt, __VA_ARGS__); \
    printf(">>>[%ld] INFO, %d, %s, %s\r\n", (long)std::time(nullptr), __LINE__, __FUNCTION__, szInfo); } while(0)

#define COMMONLOG_WARN(fmt, ...) \
    do { \
    char szInfo[COMMON_LOGINFO_SIZE] = {0}; \
    snprintf(szInfo, COMMON_LOGINFO_SIZE - 1, fmt, __VA_ARGS__); \
    printf(">>>[%ld] WRAN, %d, %s, %s\r\n", (long)std::time(nullptr), __LINE__, __FUNCTION__, szInfo); } while(0)

#define COMMONLOG_ERROR(fmt, ...) \
    do { \
    char szInfo[COMMON_LOGINFO_SIZE] = {0}; \
    snprintf(szInfo, COMMON_LOGINFO_SIZE - 1, fmt, __VA_ARGS__); \
    printf(">>>[%ld] ERROR, %d, %s, %s\r\n", (long)std::time(nullptr), __LINE__, __FUNCTION__, szInfo); } while(0)

#else

#define COMMONLOG_INFO(fmt, arg...) \
    do { \
    char szInfo[COMMON_LOGINFO_SIZE] = {0}; \
    snprintf(szInfo, COMMON_LOGINFO_SIZE - 1, fmt, ##arg); \
    printf(">>>[%ld] INFO, %d, %s, %s\r\n", (long)std::time(nullptr), __LINE__, __func__, szInfo); } while(0)

#define COMMONLOG_WARN(fmt, arg...) \
    do { \
    char szInfo[COMMON_LOGINFO_SIZE] = {0}; \
    snprintf(szInfo, COMMON_LOGINFO_SIZE - 1, fmt, ##arg); \
    printf(">>>[%ld] WRAN, %d, %s, %s\r\n", (long)std::time(nullptr), __LINE__, __func__, szInfo); } while(0)

#define COMMONLOG_ERROR(fmt, arg...) \
    do { \
    char szInfo[COMMON_LOGINFO_SIZE] = {0}; \
    snprintf(szInfo, COMMON_LOGINFO_SIZE - 1, fmt, ##arg); \
    printf(">>>[%ld] ERROR, %d, %s, %s\r\n", (long)std::time(nullptr), __LINE__, __func__, szInfo); } while(0)

#endif


